﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace AMStudio.Common
{
    public partial class LanguageTagForm : Form
    {
        protected ExceptionManager ExManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();

        private LanguageItem UIItem;
        public LanguageTagForm(LanguageItem item, bool writeable, bool empty, string currentLanguage)
        {
            this.UIItem = item;
            InitializeComponent();
            this.RefreshUI(writeable, empty, currentLanguage);
        }
        private void RefreshUI(bool writeable, bool empty, string currentLanguage)
        {
            if (this.UIItem.RelatedControl != null)
            {
                this.ribbonControl1.TitleText = "   " + this.UIItem.RelatedControl.Text + " Tag Information";
                this.ribbonControl1.Text = "   " + this.UIItem.RelatedControl.Text + " Tag Information";
            }

            this.txtLanguage.Items.Clear();
            foreach (string s in UIItem.Language.Keys)
            {
                this.txtLanguage.Items.Add(s);
            }
            this.txtLanguage.Text = currentLanguage;
            if (UIItem.Language.ContainsKey(currentLanguage))
            {
                this.txtContent.Text = UIItem.Language[currentLanguage].ToString();
            }
            else
            {
                this.txtLanguage.Items.Add(currentLanguage);
                UIItem.Language.Add(currentLanguage, string.Empty);
                this.txtContent.Text = string.Empty;
            }

            if (writeable)
            {
                //this.txtLanguage.Enabled = true;
                this.txtContent.ReadOnly = false;
            }
            else
            {
                //this.txtLanguage.Enabled = false;
                this.txtContent.ReadOnly = true;
            }
        }
        private void buttonOk_Click(object sender, EventArgs e)
        {

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {

        }

        private void UserInterfaceTagForm_Load(object sender, EventArgs e)
        {

        }

        private void txtLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (UIItem.Language.ContainsKey(this.txtLanguage.Text))
            {
                this.txtContent.Text= UIItem.Language[this.txtLanguage.Text].ToString();
            }
        }

        private void txtContent_Leave(object sender, EventArgs e)
        {
            if (UIItem.Language.ContainsKey(this.txtLanguage.Text))
            {
                UIItem.Language[this.txtLanguage.Text] = this.txtContent.Text;
            }
        }
    }
}
